package com.nbcb.fund.entity.dto;

import com.nbcb.fund.entity.code.FundCode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.File;
import java.io.Serializable;
import java.util.function.Function;

@Data
@NoArgsConstructor
@ApiModel(description = "统一返回结果")
public class FundResult<T> implements Serializable {

    @ApiModelProperty("错误代码 0:成功  其他为异常")
    private int code = 0;

    @ApiModelProperty("错误详细信息")
    private String message = "成功";

    @ApiModelProperty("返回的数据，调用失败的是，返回数据为null")
    private T data;


    public FundResult(FundCode fundCode) {
        this.code = fundCode.getCode();
        this.message = fundCode.getMessage();
    }

    /**
     * 成功
     *
     * @return EBwcrmResult
     */
    public static FundResult success() {
        return new FundResult(FundCode.SUCCESS);
    }

    /**
     * 成功
     *
     * @param data 返回数据
     * @param <T>  数据格式
     * @return EBwcrmResult
     */
    public static <T> FundResult success(T data) {
        FundResult fundResult = new FundResult(FundCode.SUCCESS);
        fundResult.setData(data);
        return fundResult;
    }

    /**
     * 系统异常
     *
     * @return EBwcrmResult
     */
    public static FundResult fail() {
        FundResult fundResult = new FundResult(FundCode.FAIL);
        return fundResult;
    }

    /**
     * 业务异常
     *
     * @param fundCode 错误码
     * @return EBwcrmResult
     */
    public static FundResult bizfail(FundCode fundCode) {
        FundResult fundResult = new FundResult(fundCode);
        return fundResult;
    }


    public static FundResult bizfail(String message){
        FundResult fundResult = new FundResult();
        fundResult.setCode(1);
        fundResult.setMessage(message);
        return fundResult;
    }

}
